package com.xmall.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmall.define.base.Result;
import com.xmall.define.constants.CommonProperties;
import com.xmall.define.dto.log.RetryLogDto;
import com.xmall.define.dto.log.RetryLogTimerTaskDto;
import com.xmall.define.request.sys.RetryLogListPageQueryRequest;
import com.xmall.sys.service.other.IRetryLogTaskService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 重试任务
 */
@RequestMapping("/service/sys/retryLogTask")
@RestController
public class RetryLogTaskController {

    @Resource
    private IRetryLogTaskService retryLogTaskService;

    @Resource
    private CommonProperties commonProperties;

    /**
     * 重试配置
     */
    @PreAuthorize("hasAuthority('sys:retryLogTask:list')")
    @GetMapping("/retryConfig")
    public Result<List<Integer>> retryConfig() {
        return Result.success(commonProperties.getLogRetryIntervalSecondsList());
    }

    /**
     * 任务列表
     */
    @PreAuthorize("hasAuthority('sys:retryLogTask:list')")
    @GetMapping("/taskList")
    public Result<List<RetryLogTimerTaskDto>> taskList() {
        return Result.success(retryLogTaskService.taskList());
    }

    /**
     * 重试日志分页列表
     */
    @PreAuthorize("hasAuthority('sys:retryLogTask:list')")
    @GetMapping("/logListPage")
    public Result<Page<RetryLogDto>> logListPage(@Validated RetryLogListPageQueryRequest request){
        Page<RetryLogDto> pageList = retryLogTaskService.logListPage(request);
        return Result.success(pageList);
    }
}
